package com.xinan.system.meet;

import java.util.List;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.xinan.utils.DateUtils;

@TableBind(tableName = "tb_meet_class")
public class TbMeetClass extends Model<TbMeetClass> {

	private static final long serialVersionUID = 1L;

	public static final TbMeetClass dao = new TbMeetClass();

	// columns START
	private String ID = "id"; // 主键
	private String MEETID = "meetid"; // 会议主键
	private String TITLE = "title"; // 课程题目
	private String CONTENT = "content"; // 内容
	private String TRANSMITCOUNT = "transmitcount"; // 转发量
	private String STARTTIME = "starttime"; // 开始时间
	private String ENDTIME = "endtime"; // 结束时间
	private String FEECLASS = "feeclass"; // 课程费用
	private String FEEPERSON = "feeperson"; // 提成
	private String TEACHER = "teacherid"; // 老师
	private String ADDRESSCITY = "addresscity"; // 地址省
	private String ADDRESSXIAN = "addressxian"; // 地址市县
	private String ADDRESSOTHER = "addressother"; // 地址具体
	private String PUBLISHTIME = "publishtime"; // 发布时间
	private String PUBLISHUSER = "publishuser"; // 发布者
	private String CREATETIME = "createtime"; // 创建时间
	private String CREATEID = "createid"; // 创建者

	public void setId(int value) {
		set(ID, value);
	}

	public int getId() {
		return get(ID);
	}

	public void setMeetid(int value) {
		set(MEETID, value);
	}

	public int getMeetid() {
		return get(MEETID);
	}

	public void setTitle(String value) {
		set(TITLE, value);
	}

	public String getTitle() {
		return get(TITLE);
	}

	public void setContent(String value) {
		set(CONTENT, value);
	}

	public String getContent() {
		return get(CONTENT);
	}

	public void setTransmitcount(int value) {
		set(TRANSMITCOUNT, value);
	}

	public int getTransmitcount() {
		return get(TRANSMITCOUNT);
	}

	public void setStarttime(String value) {
		set(STARTTIME, value);
	}

	public String getStarttime() {
		return get(STARTTIME);
	}

	public void setEndtime(String value) {
		set(ENDTIME, value);
	}

	public String getEndtime() {
		return get(ENDTIME);
	}

	public void setFeeclass(int value) {
		set(FEECLASS, value);
	}

	public int getFeeclass() {
		return get(FEECLASS);
	}

	public void setFeeperson(int value) {
		set(FEEPERSON, value);
	}

	public int getFeeperson() {
		return get(FEEPERSON);
	}

	public void setTeacher(int value) {
		set(TEACHER, value);
	}

	public int getTeacher() {
		return get(TEACHER);
	}

	public void setAddresscity(String value) {
		set(ADDRESSCITY, value);
	}

	public String getAddresscity() {
		return get(ADDRESSCITY);
	}

	public void setAddressxian(String value) {
		set(ADDRESSXIAN, value);
	}

	public String getAddressxian() {
		return get(ADDRESSXIAN);
	}

	public void setAddressother(String value) {
		set(ADDRESSOTHER, value);
	}

	public String getAddressother() {
		return get(ADDRESSOTHER);
	}

	public void setPublishtime(String value) {
		set(PUBLISHTIME, value);
	}

	public String getPublishtime() {
		return get(PUBLISHTIME);
	}

	public void setPublishuser(int value) {
		set(PUBLISHUSER, value);
	}

	public int getPublishuser() {
		return get(PUBLISHUSER);
	}

	public void setCreatetime(String value) {
		set(CREATETIME, value);
	}

	public String getCreatetime() {
		return get(CREATETIME);
	}

	public void setCreateid(int value) {
		set(CREATEID, value);
	}

	public int getCreateid() {
		return get(CREATEID);
	}

	// columns END

	public List<TbMeetClass> findAll() {
		return find("select * from tb_meet_class");
	}

	/**
	 * @param where
	 * @return Record
	 */
	public List<Record> findAlls(String where) {
		String sqlExp = " from tb_meet_class";
		if (StrKit.notBlank(where)) {
			sqlExp += " where " + where;
		}
		return Db.find("select * " + sqlExp);

	}

	public Page<TbMeetClass> page(int pageNumber, int pageSize, String where) {
		String sqlExp = "from tb_meet_class";
		if (StrKit.notBlank(where)) {
			sqlExp += " where " + where;
		}
		return paginate(pageNumber, pageSize, "select *", sqlExp);
	}

	public Page<TbMeetClass> query(int pageNumber, int pageSize, String where) {
		String sqlExp = " from ( select t.*,m.title as meettitle,city.province as cityname,th.name as teachername " //
				+ " from tb_meet_class t " //
				+ " left join tb_meet m on t.meetid=m.id" //
				+ " left join tb_meet_teacher th on t.teacherid=th.id" //
				+ " left join tb_city city on city.province_code = t.addresscity ) t ";
		if (StrKit.notBlank(where)) {
			sqlExp += " where " + where;
		}
		return paginate(pageNumber, pageSize, "select *", sqlExp);
	}

	/**
	 * 老师的课程
	 * 
	 * @date 2015年4月9日 下午4:28:48
	 * @author FLY的狐狸 369191470@qq.com
	 * @param pageNumber
	 * @param pageSize
	 * @param where
	 * @return
	 */
	public Page<TbMeetClass> showClass(int pageNumber, int pageSize, int teacherid) {
		String sqlExp = " from tb_meet_class t " //
				+ " left join tb_meet m on t.meetid=m.id where t.teacherid = ?" + " order by t.endtime desc ";
		String now = DateUtils.getCurrentDate(DateUtils.pattern_datetime);
		String statusSql = " ,( case when '" + now + "' < t.starttime then 1 " //
				+ " when '" + now + "' > t.endtime then 3 else 2 end ) as status  ";
		return paginate(pageNumber, pageSize, "select t.*,m.title as meettitle " + statusSql, sqlExp, teacherid);
	}

}
